<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\api\BaseController;
use App\Jobs\SendSPodcast;
use App\Models\DoctorModel;
use App\servers\RabbitmqServer;
use Illuminate\Http\Request;

class RabbitmqController extends BaseController
{
    /**
     *
     * @param Request $request
     * @return array|\Illuminate\Http\JsonResponse
     */
    public function production(Request $request)
    {
        try {
            $data = DoctorModel::first();
            $send = new SendSPodcast($data);
            $this->dispatch($send);
            return true;
        }catch (\Exception $e) {
            return $this->witejson(1001,'null',$e->getMessage());
        }

    }

    /**
     * 消费者测试
     * @return bool
     * @throws \Exception
     */
    public function consume()
    {
        $rabbit = new RabbitmqServer();
        $res = $rabbit->pop('sendsms');
        return $res;
    }
}
